﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace App.Lib.Service.Impl
{
	public class WeekFunction:IWeekFunction
	{
		public DateTime GetToady()
		{
			return DateTime.Now;
		}

		public int GetWeekAtYear(DateTime dt)
		{
			DateTime first=new DateTime(dt.Year,1,1);
			return ((Convert.ToInt32(first.DayOfWeek) - 2 + dt.DayOfYear)/7)+1;
		}

		public string GetWorktimeInThisWeek(DateTime dt)
		{
			DateTime start = dt;
			while (start.DayOfWeek != DayOfWeek.Monday)
			{
				start = start.AddDays(-1);
			} 
			DateTime end = start;
			while (end.DayOfWeek != DayOfWeek.Friday)
			{
				end = end.AddDays(1);
			}
			return string.Format("{0}-{1}", start.ToShortDateString().Replace('-','.'), end.ToShortDateString().Replace('-','.'));

		}

		public string GetWorktimeInNextWeek(DateTime dt)
		{
			return this.GetWorktimeInThisWeek(dt.AddDays(7));
		}
	}
}
